package com.example.liuke.guangguang.myweidgt;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.TransitionDrawable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.animation.AlphaAnimation;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.bumptech.glide.Glide;
import com.example.liuke.guangguang.R;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by liuke on 2018/11/6.
 */

public class MyImageview extends RelativeLayout{
    private ImageView imageView;
    private AlphaAnimation alphaAnimation;
    private TransitionDrawable transitionDrawable;
    private List<String> imagelist = new ArrayList<>();
    private Context context;
    public MyImageview(Context context) {
        super(context);
        this.context =context;
        initview(null);
    }

    public MyImageview(Context context, AttributeSet attrs) {

        super(context, attrs);
        this.context =context;
        initview(attrs);
    }

    private void initview(AttributeSet attributeSet){
        //获取布局
        View v = LayoutInflater.from(getContext()).inflate(R.layout.myimagelayout, this);
        imageView = (ImageView) v.findViewById(R.id.myimage);
        //淡入淡出动画需要先设置一个Drawable数组，用于变换图片
        Drawable[] drawableArray = {
                getResources().getDrawable(R.drawable.bookshelf_layer_center),
                getResources().getDrawable(R.drawable.back_card_3)
        };
        transitionDrawable = new TransitionDrawable(drawableArray);
        imageView.setImageDrawable(transitionDrawable);
        transitionDrawable.startTransition(3000);
    }

    public void setImagelist(List<String> list){
       this.imagelist =list;
    }

    //先add在remove试试 会不会出现内存泄漏
    public void startshow(){
        Glide.with(context).load(imagelist.get(0)).into(imageView);

    }


}
